Skip to content

MINOR: Support ExponentialBackoff without jitter#10455

Merged
cmccabe merged 1 commit into
apache:trunkfrom
cmccabe:allow_no_jitter
Apr 6, 2021
Merged

MINOR: Support ExponentialBackoff without jitter#10455
cmccabe merged 1 commit into
apache:trunkfrom
cmccabe:allow_no_jitter

Conversation

@cmccabe

@cmccabe cmccabe commented Mar 31, 2021

Copy link
Copy Markdown
Contributor

It is useful to allow ExponentialBackoff to be configured to work
without jitter, in order to make unit tests more repeatable.

double exp = Math.min(attempts, this.expMax);
double term = initialInterval * Math.pow(multiplier, exp);
double randomFactor = ThreadLocalRandom.current().nextDouble(1 - jitter, 1 + jitter);
double randomFactor = jitter < Double.MIN_NORMAL ? 1.0 :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to look this constant up :)

Can we just make it check if the jitter is equal to zero (or maybe <= zero)? A caller of this method setting jitter to something like 0.5 might be surprised that there is no jitter added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIN_NORMAL is 2^-1022, though. So it certainly wouldn't affect someone setting jitter = 0.5.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I misunderstood the docs and thought it was ~1. Let's keep it as-is

@cmccabe
cmccabe merged commit 137491c into apache:trunk Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants